<?php
// +----------------------------------------------------------------------
// | wttai [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.wttai.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老司机 <wutongtai@wttai.com> <http://www.wttai.com>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {

	//系统首页
    public function index(){
        //获取到广告
 
       // dump($list);exit;
        $domain_id = C('SITE');
        $p = I('p',1);
        $p = intval($p);
		//标签管理
        $tags= D('Common/Tags');
       /*  if(is_file($f=HTML_PATH.'index.html') && (NOW_TIME-filemtime($f)<36000)){
            include $f;
            exit;
        } */
        //文章基础信息表
        $document =  D('Common/Document');
      	//文章分类表 ：category_tags=1
        $category =  D('Common/category');
       
        $recommend = $document->position([4,5,6]);
        if($recommend){
            $recommend=getNameCount($recommend,'Document','pin_yin');
        }
        
        $lists = $document->getSiteArticleList($domain_id,$p,10);
        
        //增加pin_yin属性的统计
        if($lists){
            $lists=getNameCount($lists,'Document','pin_yin');
            $articleId=array_column($lists, 'id');
            //$category_tag=D('Tags')->getTags($articleId);//获取标签
            $this->_listLeftInfo($articleId);//获取标签
            $categoryAll = $category->getChildrentitle(1);//获取分类   
            $document_count = $document->getSiteArticleCount($domain_id);
            $page = ceil($document_count/10)+1;
            if ($p >= $page){
                redirect('/');
            }
            
        }
       
       
        
     
        $ad=M('AdvertiseContent');
        //获取广告内容1:Slide幻灯片2:Home_left首页左3:Home_right首页右4:Home_bottom首页中间5:Home_bottom首页底部6:Details_top详情顶部
        $topAd=$ad->where('category_id=1')->order('sort')->select();
        
        $rightAd=$ad->where('category_id=3')->order('sort')->select();
        $footerAd=$ad->where('category_id=5')->order('sort')->find();
        $centerAd=$ad->where('category_id=4')->page($p,6)->order('sort')->select(); 
        /* $ad=D('Common/AdvertiseContent');
        $topAd=$ad->get_position_ad(1);
        $rightAd=$ad->get_position_ad(3);
        $footerAd=$ad->get_position_ad(5);
        $centerAd=$ad->get_position_ad(4); */
        //dump($centerAd);exit;
        $centerAdAll=$ad->where('category_id=4')->limit(6)->order('sort')->select();
        if($p>1){
            $len=sizeof($centerAd);
            for($i=1;$i+$len<=6;$i++){
                $centerAd[$len+$i-1]=$centerAdAll[$i+$len-1];
            }
        }
        
        C('WEB_SITE_TITLE','专业服装搭配_穿衣打扮技巧_服装服饰新闻资讯_全球时尚潮流趋势_衣商网');
        C('WEB_SITE_KEYWORD',C('TITLE').'为您提供专业穿衣搭配技巧，引领穿衣打扮时尚潮流，教您穿出气质，搭出风采，每天更新服装行业资讯，是专业流行服装搭配资讯网');
        C('WEB_SITE_DESCRIPTION','服装搭配,穿衣技巧,时尚资讯,穿搭指南');
        
        $this->header();//头部内容
        //dump($rightAd);exit;
        $this->assign('topAd',$topAd);
        $this->assign('footerAd',$footerAd);
        $this->assign('centerAd',$centerAd);
        $this->assign('rightAd',$rightAd);
        
        $newDoc=$document->getSiteNewArticleList($domain_id);//最新资讯
        $newDoc=getNameCount($newDoc,'Document','pin_yin');//对pin_yin属性进行统计
        
        $this->assign('newDoc',$newDoc);
        $this->assign('lists',$lists);//列表
        $this->assign('page',$page);//分页
        $this->assign('p',$p);//当前页
        $this->assign('category',$categoryAll);//分类
        //$this->assign('tags',$category_tag);//标签
        
        $this->assign('recommend',$recommend);//首页推荐文章
        
       //echo  $this->buildHtml('index.html');
       $this->_display();
    }
}